import { defineStore } from 'pinia'
import type { TCondition, TQueryResult } from '@/api/roles'
import { getRolePages } from '@/api/roles'
export const useRoleStore = defineStore('role', () => {
  // 查询条件
  const queryCondition = reactive<TCondition>({
    name: '',
    size: 10
  })
  // 查询结果
  const queryResult = ref<TQueryResult>({
    records: [],
    size: 0,
    total: 0
  })
  // 查询方法
  const queryRoles = async (params: TCondition = { current: 1 }) => {
    Object.assign(queryCondition, params)
    const { data } = await getRolePages(queryCondition)
    if (data.code === '000000') {
      queryResult.value = data.data
    } else {
      ElMessage.error('获取角色数据失败！')
      throw new Error('获取角色数据失败！')
    }

    // console.log(queryResult.value.records)
  }
  return { queryResult, queryRoles }
})
